<?php
session_start();

if(!isset($_SESSION['userid']))//检查 userid 是否已经设置，如果没有设置，提示未登录并跳转首页
{
    echo "<script>alert('您尚未登录！')</script>";
    echo "<script>window.location.href='index.php'</script>";

}

$userid=$_SESSION['userid'];
//@$get_movieid = $_GET['id'];
include ('mysqli_connect.php');

?>

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>影视管理系统</title>
        <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
        <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
        <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        <style>
            body{
                width: 100%;
                height:auto;
                overflow: hidden;
                /*background: url("300046-106.jpg") no-repeat;*/
                background-size:cover;
                color: antiquewhite;
            }
            #query{
                text-align: center;
            }
            p{
                max-width: 50%;
                margin: auto;
                text-align:justify;
                color: black;
            }

        </style>
    </head>




<body>
<nav class="navbar navbar-default navbar-static-top" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="#">我的影视库</a>
        </div>
        <div>
            <ul class="nav navbar-nav">

                <li><a href="user_index.php">主页</a></li>
                <li class="active"><a href="user_querymovie.php">影视查询</a></li>
                <li><a href="user_sheet.php">我的收藏</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">个人信息<b class="caret"></b></a>

                    <ul class="dropdown-menu">
                        <li><a href="user_info.php">用户信息</a></li>
                        <li><a href="user_repass.php">修改密码</a></li>
                    </ul>
                </li>
                <li><a href="index.php">退出</a></li>

            </ul>
        </div>
    </div>
</nav>




<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
    $movieid = (isset($_POST['id']) ? $_POST['id'] : '');
}
else 
{
    $movieid = (isset($_GET['id']) ? $_GET['id'] : '');
}

$sqla = "select * from movie1.movie_information_table where movie_id = '{$movieid}';";
$sqlb = "select * from user_mark_table where movie_id='{$movieid}' and user_id='{$userid}';";
$resa = mysqli_query($dbc,$sqla);
$resb = mysqli_query($dbc,$sqlb);
$resulta = mysqli_fetch_array($resa);
$resultb = mysqli_fetch_array($resb);
$movie_name = $resulta['movie_Chinese_name'];
if(($resulta != false)&&($resultb != false))
{

    $user_marking = $resultb['user_marking'];
    $marking_content = $resultb['marking_content'];
    $marking_time = $resultb['marking_time'];
}
else
{

    $user_marking = "暂无评分";
    $marking_content = "暂无评语";
    $marking_time = "暂无编辑记录";
}


?>


<h1 style = "text-align: center; color: darkblue"><strong>修改&emsp13;<?php echo $movie_name?>&emsp13;的评价</strong></h1><br><br>

<br><br><br>
<p><strong>电影ID：</strong><?php echo $movieid?></p>
<p><strong>我的评分：</strong><?php echo $user_marking?></p>
<p><strong>我的评语：</strong><?php echo $marking_content?></p>
<p><strong>最后编辑于：</strong><?php echo $marking_time?></p>
<br>

<div style="padding: 10px 500px 10px;">
    <form  action="user_change_mark.php?" method="POST" style="text-align: center" class="bs-example bs-example-form" role="form">
        <div id="login">

            <div class="input-group"><span  class="input-group-addon">评分</span><input value="" name="user_marking" type="text" placeholder="填写0-10之间的数字" class="form-control"></div><br/>
            <div style="display:hidden;"><input value=<?php echo $movieid?> name="id" type="hidden" placeholder="填写0-10之间的数字" class="form-control"></div>
            <div class="form-group">
                <label for="name"; style="color: black">评语：</label>
                <textarea name="marking_content" type="text"  class="form-control" rows="4"></textarea>
            </div>

            <label><input type="submit" value="确认" class="btn btn-default"></label>
            <label><input type="reset" value="重置评论" class="btn btn-default"></label>
        </div>
    </form>
</div>





<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{


    //$get_movieid = (isset($_GET['id']) ? $_GET['id'] : '');
    $get_movieid = (isset($_POST['id']) ? $_POST['id'] : '');
    $marking = $_POST["user_marking"];
    $content = $_POST["marking_content"];
    $nowtime = date('Y').'年'.date('m').'月'.date('d').'日';

    echo "<script>alert('id值为：'.'{$get_movieid}')</script>";



    // 这一句，死都传不了参，插进数据库的movie_id永远都是空值！！！！不知道怎么回事！！！
    $sqlm="replace into user_mark_table(user_id,movie_id,user_marking,marking_content,marking_time)
                values('{$userid}','{$get_movieid}','{$marking}','{$content}','{$nowtime}');
                ";


    //下面的sql语句测试是正常工作的！
//    $sqlm="replace into user_mark_table(user_id,movie_id,user_marking,marking_content,marking_time)
//                values('6','30','9.9','测试3','2019年12月11日');
//                ";
    $resm=mysqli_query($dbc,$sqlm);


    if($resm==1)
    {

        echo "<script>alert('修改成功！')</script>";
        echo "<script>window.location.href='user_querymovie.php'</script>";

    }
    else
    {
        echo "<script>alert('修改失败！请重新输入！');</script>";

    }

}

?>

